package question16;

import java.util.Arrays;

public class question16 {


    StringBuilder s = new StringBuilder();
    String ans = "";
    boolean[] visited = new boolean[4];


    public String largestTimeFromDigits(int[] arr) {
        String[] arr1 = new String[3];
        int[] array = Arrays.stream(arr1).mapToInt(Integer::valueOf).toArray();
        dfs(arr);
        return  ans.length() == 0 ? "" : ans.substring(0, 2) + ":" + ans.substring(2);
    }




    public void dfs(int[] arr) {
        if (s.length() == 4) {
            int hour = Integer.parseInt(s.substring(0, 2));
            int minute = Integer.parseInt(s.substring(2, 4));
            if (hour < 24 && minute <= 59 && s.toString().compareTo(ans) > 0) {
                ans = s.toString();
            }
            return;
        }
        for(int i = 0; i < arr.length; i++) {
            if (visited[i]) {
                continue;
            }
            s.append(arr[i]);
            visited[i] = true;
            dfs(arr);
            visited[i] = false;
            s.deleteCharAt(s.length()-1);
        }
    }

    public static void main(String[] args) {
        String s1 = new question16().largestTimeFromDigits(new int[]{1, 2, 3, 4});
        System.out.println(s1);
    }
}
